package com.hdaccp.xingmu.service.impl;

import com.hdaccp.xingmu.dao.DanyuanDao;
import com.hdaccp.xingmu.entity.Danyuan;
import com.hdaccp.xingmu.entity.House;
import com.hdaccp.xingmu.poi.WriteExcel;
import com.hdaccp.xingmu.service.DanyuanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

@Service
public class DanyuanServiceImpl implements DanyuanService{
    @Autowired
    private DanyuanDao danyuanDao;

    @Override
    public InputStream getInputStream() throws Exception {
        String[] title=new String[]{"楼宇编号","所属小区","楼层数","房屋数"};
        List<Danyuan> plist=danyuanDao.findAll();
        List<Object[]>  dataList = new ArrayList<Object[]>();
        for(int i=0;i<plist.size();i++){
            Object[] obj=new Object[4];
            obj[0]=plist.get(i).getId();
            obj[1]=plist.get(i).getName();
            obj[2]=plist.get(i).getLou();
            obj[3]=plist.get(i).getFang();
            dataList.add(obj);
        }
        WriteExcel ex = new WriteExcel(title, dataList);
        InputStream in;
        in = ex.export();
        return in;
    }
}
